﻿
using LbangCMS.EFModels;
using LbangCMS.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LbangCMS.Controllers
{
    public class JobController : Controller
    {
        // GET: Job
        public ActionResult Index()
        {
            var jobs = GetJobList();
            var model = new List<JobListModel>();
            if(jobs!=null&&jobs.Any())
            {
                foreach (var item in jobs)
                {
                    model.Add(new JobListModel() {
                        ID = item.ID,
                        Description = item.Description,
                        Experience = item.Experience,
                        JobName = item.JobName,
                        Location = item.Location,
                        Quantity = item.Quantity,
                    });
                }
            }
            return View(model);
        }

        public ActionResult Logos()
        {
            var code = "logos";
            var page = GetSinglePage(code);

            if (page == null)
            {
                return RedirectToAction("NotFound");
            }
            else
            {
                SinglePageModel model = new SinglePageModel();
                model.Title = page.Title;
                model.Body = page.Body;
                ViewBag.Title = page.Title;
                return View(model);
            }
        }

        private SinglePage GetSinglePage(string code)
        {
            using (var db = new Database())
            {
                return db.SinglePages.Where(o => o.Code == code).FirstOrDefault();
            }
        }

        private List<Job> GetJobList()
        {
            using (var db = new Database())
            {
                return db.Jobs.Where(o => o.Status == 1).OrderBy(o => o.ID).ToList();
            }
        }
    }
}